package com.lbiuse.biz.manage.user.dao;

import org.apache.commons.dbutils.ResultSetHandler;
import org.bidtime.dbutils.jdbc.dao.BasicDAO;
import org.springframework.stereotype.Repository;

import java.sql.SQLException;
import java.util.Map;

@Repository
public class UserDAO extends BasicDAO {


	public <T> T getUserSelecter(ResultSetHandler h,Map<String, Object> params,
			Integer nPageIdx, Short nPageSize) throws SQLException {
		return (T)queryEx("selectSqlOfUserSelecter", h, params, nPageIdx,
				(int) nPageSize);
	}
/*
	*//**
	 * {获取店内用户列表}
	 * 
	 * @param shopId
	 *            : 店Id nPageIdx nPageSize
	 * @return 返回json结果
	 * @exception {说明在某情况下,将发生什么异常}
	 *//*
	public GsonEbRst getGsonOfShopId(Integer shopId, Integer nPageIdx,
			Short nPageSize) throws SQLException {
		Object[] params = new Object[] { shopId };
		return getGsonOfParams("select_cust_of_shopId", params, nPageIdx,
				nPageSize, true);
	}

	public GsonEbRst getGsonOfUserId(String userId) throws SQLException {
		Object[] params = new Object[] { userId };
		return getGsonOfParams("select_of_deptId", "select_of_deptId_json", params);
	}

	public boolean isExistsOfUserIdPassword(Object id, String sPassword)
			throws SQLException {
		Object[] params = new Object[] { id, sPassword };
		return queryForInt("exitUserIdPs", params, 0) > 0 ? true : false;
	}

	public int changePs(Object id, String newPs, String oldPs)
			throws Exception {
		Object[] params = new Object[] { newPs, oldPs, id, oldPs };
		return update("updatePs", params);
	}

//	public Object[] getUserIdStatusOfLoginName(String loginUser,
//			String sPassword) throws SQLException {
//		Object[] params = new Object[] { loginUser, sPassword };
//		return SqlLoadUtils.getObjectListOfParams(this.getClass(),
//				"getUserIdStatusOfLoginName", params);
//	}
	
	public GsonHeadOneRow getUserIdStatusOfLoginName(String loginUser,
			String sPassword) throws SQLException {
		Object[] params = new Object[] { loginUser, sPassword };
		return getOneRowOfParams("getUserIdStatusOfLoginName", params);
	}
	
	

	public int insertUserLogin(String sUserName, String sSessionId) {
		// String sql =
		// "insert into user_log(userName,tmCreate,operType,sessionId)" +
		// " values(?,?,?,?)";
		// Object[] params = new Object[]{sUserName, new java.util.Date(),
		// "login", sSessionId};
		int nn = 1;// this.update(sql, params);
		return nn;
	}

	// public Integer getUserIdOfIdNumber(Object idNumber) throws SQLException {
	// Object[] params = new Object[]{idNumber};
	// return queryForInt("selectSqlIdNumber", params, 0);
	// }

	// private void decryptPws(GsonEbRst g) {
	// if (g != null) {
	// g.decryIdxAES("password");
	// }
	// }

	public Integer getIsLoginName(String valueOfName) throws SQLException {
		Object[] params = new Object[] { valueOfName };
			
		return queryForInt("selectSqlIsLogin", params, 0);
	}

	public Integer getIsId(Long lMaxCustId) throws SQLException {
		Object[] params = new Object[] { lMaxCustId };
		return queryForInt("selectSqlIsID", params, 0);
	}

	public Long getUserIdOfEmail(String email) throws SQLException {
		Object[] params = new Object[] { email };
		return queryForLong("getUserIdOfEmail", params, 0l);
	}

	public boolean existUserOfMp(String mp) throws SQLException {
		Object[] params = new Object[] { mp };
		return queryForBoolean("existsUserOfMp", params, false);
	}
	
	public GsonHeadOneRow getUserOfUserId (Long id) throws SQLException {
		Object[] params = new Object[] { id };
		return getOneRowOfParams("getSqlOfId", params);
	}
	
	public String getDutyNameOfUserId(Long id) throws SQLException {
		Object[] params = new Object[] { id };
		return queryForString("getdutyNameOfId", params, "");
	}
	
	public int updateOutIdOfId (Long outId,Long id) throws SQLException{
		Object[] params = new Object[] { outId,id };
		return update("updateOutIdOfOfId",params);
	}
	
	public GsonEbRst getUserList(Map<String, Object> params, Integer nPageIdx,
			Short nPageSize) throws SQLException {
		if(nPageIdx>0){
			nPageIdx--;
		}
		return getGsonOfParams("select_cust_list",params,
				nPageIdx, nPageSize, true);
	}
	public GsonEbRst getUserList2(Map<String, Object> params, Integer nPageIdx,
			Short nPageSize) throws SQLException {
		return getGsonOfParams("select_cust_list",params,
				nPageIdx, nPageSize, true);
	}
	public GsonHeadManyRows getUserListAll(Map<String, Object> params) throws SQLException {
		
		return getManyRowsOfParams("select_cust_list",params
				);
	}

	public int updateIndex(String index, String id )
			throws SQLException {
		Object[] params = new Object[] {index, id}; 
		return update("updateIndex", params ) ;
				
	}
	public int updateImage(String image, long id )
			throws SQLException {
		Object[] params = new Object[] {image, id}; 
		return update("updateImage", params ) ;
				
	}

	public GsonHeadOneRow selectUserById(Long userId) {
		// TODO Auto-generated method stub
		return null;
	}
	
	public GsonHeadManyRows getAllUserIdByManagerId(Long userId) throws SQLException {
		Map<String, Object> params = new HashMap<String,Object>();
		params.put("userId", userId);
		return getManyRowsOfParams("getAllUserIdByManagerId",params
				);
	}*/
	
}
